# -*- coding: utf-8 -*-
"""
@Time ： 2023/9/14 8:38
@Auth ： y.h
@File ：dict_util.py
@IDE ：PyCharm
@Motto：The sooner you start to code, the longer the program will take. —— Roy Carlson
"""



# 不建议使用三层for循环,非必须不要用!
# 二维以上的字典建议先拆包,再使用,否则算法的 时间复杂度为O(n^2++)

# 字典操作工具
def dict_one_dimensional_pop(data_dict: dict, keys, key_or_value=True) -> dict:
    """
    一维字典删除指定key或value
    :param key_or_value: 判断是根据key还是value删除 true = key,False = Value 默认是key
    :type key_or_value: bool
    :param data_dict: 源字典
    :type data_dict: dict
    :param keys: 要删掉的key
    :type keys: list[str|int]
    :return: 筛选后的字典
    :rtype: dict
    """

    if key_or_value:
        for key in keys:
            # 判断字典内是否包含该键
            if key in data_dict.keys():
                # 包含则删除
                data_dict.pop(key)
    else:
        # 用的时候再写
        pass
    # 返回处理后的字典
    return data_dict


def dict_two_dimensional_pop(data_dict: dict, keys, key_or_value=True) -> dict:
    """
        二维字典删除指定key或value
        :param key_or_value: 判断是根据key还是value删除 true = key,False = Value 默认是key
        :type key_or_value: bool
        :param data_dict: 源字典
        :type data_dict: dict
        :param keys: 要删掉的key
        :type keys: list[str|int]
        :return: 筛选后的字典
        :rtype: dict
        """
    if key_or_value:
        # 二维数组拆解
        for one_dimensional_dict in data_dict:
            # 键列表遍历
            for key in keys:
                # 判断
                if key in one_dimensional_dict.keys():
                    # 删除
                    one_dimensional_dict.pop(key)
    else:
        # 用的时候再写
        pass
    # 返回处理后的字典
    return data_dict


